home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7611 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: linus.mitre.org!mbunix!jrv
  2. From: jrv@mbunix.mitre.org (Jim Van Zandt)
  3. Newsgroups: comp.lang.c
  4. Subject: Determining endianness - portable way?
  5. Date: 27 Feb 1996 18:35:11 GMT
  6. Organization: The MITRE Corporation
  7. Message-ID: <4gvisv$fc@linus.mitre.org>
  8. Reply-To: jrv@vanzandt.mv.com
  9. NNTP-Posting-Host: mbunix.mitre.org
  10.  
  11.  
  12. I have an application that writes short ints into a binary file, and
  13. want to make it portable to both little- and big-endian machines.  I
  14. would like to use htons() (from BSD networking), but I find that
  15. Borland for one does not this in its library.  Borland does provide
  16. bswap(), but how I do tell whether to call it?  (Incidently, I was
  17. surprised to find that Stevens does not address this in his book
  18. Advanced Programming in the Unix Environment.)
  19.  
  20. Is there a portable way to:
  21.  
  22.   - Put a short int into "network order"?
  23.  
  24.   - Discover the endianness of the intended architecture (e.g. standard
  25. #define)?
  26.  
  27.   - Determine the endianness of the current architecture
  28. (i.e. test program)?
  29.  
  30.                                    - Jim Van Zandt
  31.  
  32. (email replies would be appreciated)
  33.